﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DepartmentManagement
{
    public partial class TestForm : Form
    {
        private Encoding txtEncodeType = Encoding.Default;

        public TestForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string show = string.Empty;

            show += "PREFIX ==============>" + Environment.NewLine;
            foreach (DataAccess.PrefixType pt in GlobalVariable.GLB_DB_SCHEMA.Prefixes)
            {
                show += "Prefix Name:" + pt.Name + Environment.NewLine;
                show += "\tDescription:" + pt.Description + Environment.NewLine;
            }
            show += Environment.NewLine;

            show += "TABLE ==============>" + Environment.NewLine;
            foreach (DataAccess.TableType tt in GlobalVariable.GLB_DB_SCHEMA.Tables)
            {
                show += "Table Name:" + tt.FullName + Environment.NewLine;
                show += "\tTable Prefix:" + tt.Prefix + Environment.NewLine;
                show += "\tTable PureName:" + tt.PureName + Environment.NewLine;
                show += "\tTable Description:" + tt.Description + Environment.NewLine;
                show += "\tTable Columns ==============>" + Environment.NewLine;

                foreach (DataAccess.ColumnType ct in tt.Column)
                {
                    show += "\t\tColumn Name:" + ct.Name + Environment.NewLine;
                    show += "\t\tColumn Type:" + ct.Type + Environment.NewLine;
                    show += "\t\tColumn Description:" + ct.Description + Environment.NewLine;
                }
            }

            textBox1.Text = show;
        }

        private void txtEncode_Click(object sender, EventArgs e)
        {
            string base64 = string.Empty;
            string qp = string.Empty;
            if (null != txtCommonString.Text && string.Empty != txtCommonString.Text)
            {

                base64 = CodingFunction.Base64Encode(txtCommonString.Text, txtEncodeType);
                qp = CodingFunction.QPEncode(txtCommonString.Text, txtEncodeType);

            }
            txtBase64.Text = base64;
            txtQP.Text = qp;
        }

        private void btnBase64Decode_Click(object sender, EventArgs e)
        {
            string commText = string.Empty;
            string qp = string.Empty;

            if (null != txtBase64.Text && string.Empty != txtBase64.Text)
            {
                commText = CodingFunction.Base64Decode(txtBase64.Text, txtEncodeType);
                qp = CodingFunction.QPEncode(commText, txtEncodeType);
            }

            txtQP.Text = qp;
            txtCommonString.Text = commText;
        }

        private void btnQPDecode_Click(object sender, EventArgs e)
        {
            string commText = string.Empty;
            string base64 = string.Empty;

            if (null != txtQP.Text && string.Empty != txtQP.Text)
            {
                commText = CodingFunction.QPDecode(txtQP.Text, txtEncodeType);
                base64 = CodingFunction.Base64Encode(commText, txtEncodeType);
            }

            txtBase64.Text = base64;
            txtCommonString.Text = commText;
        }

        private void drpEncoding_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (drpEncoding.SelectedText)
            {
                case "Default":
                    break;
                case "ASCII":
                    txtEncodeType = Encoding.ASCII;
                    break;
                case "UTF8":
                    txtEncodeType = Encoding.UTF8;
                    break;
                case "Unicode":
                    txtEncodeType = Encoding.Unicode;
                    break;
                case "BIG5":
                    txtEncodeType = Encoding.GetEncoding("big5");
                    break;
                case "GB2312":
                    txtEncodeType = Encoding.GetEncoding("gb2312");
                    break;
                case "UTF16":
                    txtEncodeType = Encoding.GetEncoding("utf-16");
                    break;
                case "GB18030":
                    txtEncodeType = Encoding.GetEncoding("GB18030");
                    break;
                case "HZ":
                    txtEncodeType = Encoding.GetEncoding("hz-gb-2312");
                    break;
                default:
                    break;
            }
        }
    }
}
